home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 16542 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.7 KB

  1. Path: news.nyu.edu!schonberg!dewar
  2. From: dewar@cs.nyu.edu (Robert Dewar)
  3. Newsgroups: comp.lang.ada,comp.lang.c,comp.lang.c++,comp.edu
  4. Subject: Re: ANSI C and POSIX (was Re: C/C++ knocks the crap out of Ada)
  5. Date: 10 Apr 1996 23:16:27 -0400
  6. Organization: Courant Institute of Mathematical Sciences
  7. Message-ID: <dewar.829192575@schonberg>
  8. References: <JSA.96Feb16135027@organon.com> <dewar.828879781@schonberg> <4k9qhe$65r@solutions.solon.com> <dewar.828936837@schonberg> <4kb2j8$an0@solutions.solon.com> <dewar.829011320@schonberg> <4khevn$26a@janus.pec.co.nz>
  9. NNTP-Posting-Host: schonberg.cs.nyu.edu
  10. X-Newsreader: NN version 6.5.0 (NOV)
  11.  
  12. John suggested
  13.  
  14. "    /* Try to protect the user a little bit from left over garbage: */
  15.     memset(&buf[avail], nbytes-avail, 0);  /* zero out buf[avail..nbytes-1] */
  16.     return avail;"
  17.  
  18. Interesting, the spec is really not clear on whether this is a valid
  19. implementation. I can easily imagine a programmer whose unwritten
  20. rules would rule out this interpretation and who might assume that
  21. code which
  22.  
  23.   (a) preinitialized the buffer to blanks
  24.   (b) used read to read into part of this buffer
  25.  
  26. should be able to expect trailing spaces and not zeroes,
  27.  
  28. but here again, the spec is insufficiently clear I would say, so this is
  29. another nice example of possible portability problems that come from
  30. a vague spec.
  31.  
  32. That trailing spaces code will probably work in most (all) implementations
  33. of read, and I can imagine some (injudicious? or perhaps informed by
  34. a different set of "unwritten rules") programmer assuming it would work.
  35. Then an implementatoin would do as John suggested, which certainly is
  36. not unreasonable, and lo and behold, another portability problem that
  37. could have been prevented by a precise spec.
  38.  
  39.